<?php
class MemberAction extends CommonAction {
	
	function _initialize(){
		parent::_initialize();
	}
	
    function index(){
    	$true_name = $this->_param('true_name', 'trim');
    	$mobile = $this->_param('mobile', 'trim');
    	$map = array();
    	if($true_name)
    		$map['true_name'] = $true_name;
    	if($mobile)
    		$map['mobile'] = $mobile;
    	
    	$model = D('member');
    	$count = $model->where($map)->count('user_id');
    	
    	if ($count > 0) {
    		import("ORG.Util.Page");
    		
    		//分页查询数据
    		$p = new Page($count, 20);
    		$voList = $model->where($map)->order("`user_id` desc")->limit($p->firstRow . ',' . $p->listRows)->select();
    		//分页跳转的时候保证查询条件
    		foreach ($map as $key => $val) {
    			if (!is_array($val)) {
    				$p->parameter .= "$key=" . urlencode($val) . "&";
    			}
    		}
    		
    		//分页显示
    		$page = $p->show();
    		
    		//模板赋值显示
    		$this->assign('order_url', U('Order/index/', array('user_id'=>'1')));
    		$this->assign('list', $voList);
    		$this->assign("page", $page);
    	}
    	cookie('_currentUrl_', __SELF__);
    	$this->display();
    }
    
    function detail(){
    	$user_id = $this->_request('user_id', 'intval');
    	$model = D('Member');
    	$user_info = $model->find($user_id);
    	
    	$this->assign('status_arr', $model->status_arr);
    	$this->assign('user_info', $user_info);
    	$this->display();
    }
    
    /* function add(){
    	if($this->isPost()){
	    	$model = D('Article');
	    	if (false === $model->field('cat_id,title,content')->create()) {
	    		$this->error($model->getError());
	    	}
	    	//$model->add_time = date('YmdHis');
	    	//保存当前数据对象
	    	$list = $model->add();
	    	if ($list !== false) { //保存成功
	    		$this->success('新增成功!',cookie('_currentUrl_'));
	    	} else {
	    		//失败提示
	    		$this->error('新增失败!'.$model->getDbError());
	    	}
    	}
    	else{
    		$this->assign('cat_opt', array('1'=>'gaga'));
    		$this->display();
    	}
    }
    
    function edit(){
    	$id = $this->_request('id');
    	
    	if($id == '')
    		$this->error('参数错误!');
    	
	    $model = D('Article');
    	$info = $model->find($id);
    	
    	if($this->isPost()){
	    	if (false === $model->field('cat_id,title,content')->create()) {
	    		$this->error($model->getError());
	    	}
	    	//$model->edit_time = date('YmdHis');
	    	//保存当前数据对象
	    	$list = $model->add();
	    	if ($list !== false) { //保存成功
	    		$this->success('编辑成功!',cookie('_currentUrl_'));
	    	} else {
	    		//失败提示
	    		$this->error('编辑失败!');
	    	}
    	}
    	else{
    		$this->assign('vo', $info);
    		$this->assign('cat_id', $info['cat_id']);
    		$this->display();
    	}
    } */
    
    function delete(){
    	$id = $this->_request('id');
    	 
    	if($id == '')
    		$this->error('参数错误!');
    	 
    	$model = D('Article');
//     	$flag = $model->where(array('id'=>$id))->delete();
    	$flag = $model->delete($id);
    	
    	if(!$flag)
    		$this->error('删除失败!');
    	else
    		$this->success('删除成功!',cookie('_currentUrl_'));
    	
    }
    
    
}